﻿@model IEnumerable<YQBlog.Models.CategoryModel>
@using res = Resource.Views.Admin.Admin;     
@{YQBlog.General.GeneralConfigInfo ci = ViewBag.CI as YQBlog.General.GeneralConfigInfo;}
@section MenuInfo{
<ul> 
    <li>@Html.ActionLink("-"+ res.ManagementHome+" -", "Index", "Admin")</li>
    <li>@Html.ActionLink("-" + res.ContentManagement + " -", "AdminArticle", "Admin", new { tid = 1 }, null)</li>
    <li class="selected">
        <span class="selected-arrow">&nbsp;</span>
        <a href="###">- @res.Configuration -</a>
        <ul>
            <li>@Html.ActionLink(res.BasisSet, "AdminBaseConfig", "Admin")</li>
            <li  class="selected">@Html.ActionLink(res.CategorySettings, "AdminCategorySort", "Admin")</li>
        </ul>
    </li>
    <li>@Html.ActionLink("-" + res.UserManagement + " -", "AdminUserList", "Admin")</li>
</ul>
}
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.dragsort-0.5.1.min.js")" type="text/javascript"></script>

<div id="mainContent">
        <div id="leftBox">
          <div id="pagePath">
          @res.Location：@res.CategorySettings
          </div>

          <div class="contentBox">
            <div class="contentBoxTop">
              <h3>@res.CategorySettings</h3>
            </div>
            <div class="innerContent">
            <div><a class="iconAdd" style="padding-left:20px;display:block;cursor:pointer;" onclick="AddRootCate();">@res.Add</a> </div>
                    @if ((Model as IEnumerable<YQBlog.Models.CategoryModel>).Count() > 0)
                    {  
                        <ul class="catelist">
                            @foreach (var item in Model)
                            {
                                    <li id="@item.CateId" @{if (item.ParentId == "0")
                                                            {
                                                                @:class="cl_root"
                                                                }}>
                                        @Html.Raw(item.CateName)  
                                        (@item.CateId)
                                    </li>
                            } 
                        </ul>
                    }
             <div class="catelink">@Html.ActionLink(res.ManualManagement, "AdminCategory", "Admin")</div>
            </div><!--end of #box-3-->
          </div>
      </div><!-- end of #leftBox -->
              
  </div><!-- end of #content -->
@section Js{
<script type="text/javascript">
    $(function () {
        $(".catelist").dragsort({ dragSelector: "li", dragBetween: false, dragEnd: saveOrder, placeHolderTemplate: "<li></li>" });

        SetCateOperate();

        $(".cate-operate .iconAdd").live("click", function () {
            window.location = "/BlogAdmin/Admin/AdminCategoryAdd?id=" + $(this).parent().parent().attr("id");
        });
        $(".cate-operate .iconEdit").live("click", function () {
            window.location = "/BlogAdmin/Admin/AdminCategoryEdit?id=" + $(this).parent().parent().attr("id");
        });
        $(".cate-operate .iconDel").live("click", function () {
            if (confirm("@(res.CategoryDel_Tip)"))
                $.post('/BlogAdmin/Admin/AdminCategoryDel', { id: $(this).parent().parent().attr("id") }, function (data) {
                //$('.innerContent').html(data);
                    window.location = "/BlogAdmin/Admin/AdminCategorySort";
            });
        });
    });

    function AddRootCate() {
        window.location = "/BlogAdmin/Admin/AdminCategoryAdd?id=0";
    }

    function SetCateOperate() {
        $(".catelist li").append("<div class=\"cate-operate\"><a class=\"iconDel\"></a><a class=\"iconEdit\"></a><a class=\"iconAdd\"></a></div>"); 
    }

	function saveOrder() {
	    var t = "";
	    $(".catelist li").each(function (index, domEle) {
	        t = t + $(this).attr("id") + ",";
	    });
	    $.post('/BlogAdmin/Admin/AdminCategorySort', { ids: t }, function (data) {
	        $(".catelist").html(data);
	        SetCateOperate();
	    });
	}
</script>
}